package com.hero.controller;

import com.hero.entity.Organization;
import com.hero.service.OrganizationService;
import com.hero.utils.ResponseJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 组织机构表(Organization)表控制层
 *
 * @author makejava
 * @since 2021-06-29 19:38:19
 */
@CrossOrigin
@RestController
@RequestMapping("/org")
public class OrganizationController {
    /**
     * 服务对象
     */
    @Autowired
    private OrganizationService organizationService;

    @PostMapping("/insert")
    public ResponseJson add(@RequestBody Organization entity){
        organizationService.insert(entity);
        return ResponseJson.success();
    }

    @PutMapping("/update")
    public ResponseJson edit(@RequestBody Organization entity){
        organizationService.update(entity);
        return ResponseJson.success();
    }

    @DeleteMapping("/delete/{id}")
    public ResponseJson remove(@PathVariable Integer id){
        organizationService.deleteById(id);
        return ResponseJson.success();
    }
    @DeleteMapping("/deletes/{ids}")
    public ResponseJson removes(@PathVariable  Integer[] ids){
        organizationService.deleteByIds(ids);
        return ResponseJson.success();
    }
//    @DeleteMapping("/remove")
//    public ResponseJson removeBatch(Integer[] id){
//        organizationService.removeBatch(id);
//        return ResponseJson.success();
//    }


    @GetMapping("/find/{id}")
    public ResponseJson findById(@PathVariable Integer id){
        return ResponseJson.success(organizationService.queryById(id));
    }

    @GetMapping("/find")
    public ResponseJson find(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize,
                             Organization organization){
        return ResponseJson.success(organizationService.find(pageNum, pageSize,organization));
    }

    @GetMapping("/findAll")
    public ResponseJson findAll(Organization organization){
        return ResponseJson.success(organizationService.queryAll(organization));
    }

}
